/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.dao.utils;

import java.util.HashMap;
import java.util.Map;

import lt.marsrutai.mobile.android.dao.APIFunctionConstants;
import lt.marsrutai.mobile.android.dao.dto.ArrivalTimeDto;
import lt.marsrutai.mobile.android.dao.dto.BusStopDto;
import lt.marsrutai.mobile.android.dao.dto.DaysOfWeekDto;
import lt.marsrutai.mobile.android.dao.dto.ScheduleDto;
import android.util.Pair;

/**
 * <p>Node - class configuration for a specific function call.</p>
 * <p>While the current json parser uses a convention to resolve class names for nodes, some responses, however, 
 * do not honor that convention. Therefore this class stores configuration entries for such cases.
 * </p>
 * <p>Each configuration is identified by a function name and node name:<br/>
 * <code>{functionName, nodeName} -> {nodeClass}</code>
 * </p>
 * 
 * @author Justas
 *
 */
public class NodeClassConfiguration {

    private static Map<Pair<String, String>, Class<?>> nodeClassConfiguration = new HashMap<Pair<String, String>, Class<?>>();
    
    static {
        add(APIFunctionConstants.FUNCTION_GET_STOPS, "SchedulesAtStop", ScheduleDto.class);
        add(APIFunctionConstants.FUNCTION_GET_RUN_BY_ID, "RunningDays", DaysOfWeekDto.class);
        add(APIFunctionConstants.FUNCTION_GET_RUN_BY_ID, "Times", ArrivalTimeDto.class);

        add(APIFunctionConstants.FUNCTION_FIND_ROUTES, "StartStop", BusStopDto.class);
        add(APIFunctionConstants.FUNCTION_FIND_ROUTES, "EndStop", BusStopDto.class);
    }
    
    public static void add(String functionName, String node, Class<?> nodeClass) {
        nodeClassConfiguration.put(new Pair<String, String>(functionName, node), nodeClass);
    }
    
    /**
     * Gets the configured class for <code>functionName + nodeName</code>
     * 
     * @param functionName
     * @param nodeName
     * @return
     */
    public static Class<?> get(String functionName, String nodeName) {
        return nodeClassConfiguration.get(new Pair<String, String>(functionName, nodeName));
    }
}
